<template>
  <div class="iframeBox">
      <iframe :key="key" id="iframeTag" :src="src" frameborder="0"></iframe>
  </div>
</template>

<script>
// import { getCookie } from "../assets/js/storage.js";
import { mapGetters, mapState } from "vuex";

export default {
  data() {
    return {
      src: "",
      key: Date.parse(new Date()),
      urlObj: {}
    };
  },
  created() {
    let _this = this;
    $(window).resize(function() {
      _this.key = Date.parse(new Date());
    });
    _this.pitchUrl(
      JSON.parse(window.sessionStorage.getItem("allMenu"))
    )
  },
  computed: {
    ...mapGetters(["getIsHideSideBar"]),
  },
  watch: {
    getIsHideSideBar: function() {
      this.key = Date.parse(new Date());
    }
  },
  methods: {
    pitchUrl(Arr) {
      let subArr;
      Arr.forEach(element => {
        if (element.permission == "STAT") {
          subArr = element.childList;
        }
      });
      subArr.forEach(element => {
        switch (element.url) {
          case "/stat/trader":
            this.urlObj.statTrader = element.externalLinks;
            break;
          case "/stat/parkingflow":
            this.urlObj.statParkingflow = element.externalLinks;
            break;
          case "/stat/parkingtime":
            this.urlObj.statParkingtime = element.externalLinks;
            break;
          default:
            break;
        }
      });
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      // console.log(vm.allMenu.list[7].childList);
      // console.log(vm.allMenu);
      // console.log("to, from, next", to.name, from, next);
      let routerName = to.name;
      switch (routerName) {
        case "stat_trader":
          vm.src = vm.urlObj.statTrader;
          break;
        case "stat_parkingflow":
          vm.src = vm.urlObj.statParkingflow;
          break;
        case "stat_parkingtime":
          vm.src = vm.urlObj.statParkingtime;
          break;
        default:
          break;
      }
      vm.key = Date.parse(new Date());
    });
  }
};
</script>

<style lang="less" scoped>
.iframeBox {
  height: 100%;
  iframe {
    width: 100%;
    height: 100%;
  }
}
</style>